<template>
	<view>
		<view class="box">
			<view class="Grid Grid--center" style="padding: 20rpx 30rpx 0;">
				<view class="Grid-cell">￥{{data.extractCount || 0}}</view>
				<view><u-button style="warning" text="提现" @click="goUserCash"></u-button></view>
			</view>
			<view class="Grid Grid--1of2" style="text-align: center; padding: 20rpx 0;">
				<view class="Grid-cell">
					<view>累计收益</view>
					<view>￥{{data.lastDayCount || 0}}</view>
				</view>
				<view class="Grid-cell">
					<view>待收益</view>
					<view>￥{{data.commissionCount || 0}}</view>
				</view>
			</view>
		
		</view>
		
		<view class="order-index" ref="container" style="position: relative;">
			<image src="https://qny.yijiumy.com/orderIndex.png" mode="widthFix" class="image" />
			<view class="header acea-row">
				<view class="item" @click="goAdminOrderList(0)">
					<view class="num">{{ census.orderCount.unpaidCount }}</view>
					<view>待付款</view>
				</view>
				<view class="item" @click="goAdminOrderList(1)">
					<view class="num">{{ census.orderCount.unshippedCount }}</view>
					<view>待发货</view>
				</view>
				<view class="item" @click="goAdminOrderList(2)">
					<view class="num">{{ census.orderCount.receivedCount }}</view>
					<view>已发货</view>
				</view>
				<view class="item" @click="goAdminOrderList(3)">
					<view class="num">{{ census.orderCount.evaluatedCount }}</view>
					<view>待评价</view>
				</view>
				<view class="item" @click="goAdminOrderList(4)">
					<view class="num">{{ census.orderCount.refundCount }}</view>
					<view>退款</view>
				</view>
			</view>
			<view class="wrapper">
				<view class="title">
					<text class="iconfont icon-shujutongji"></text>数据统计
				</view>
				<view class="list acea-row">
					<view class="item" @click="goStatistics({type:'price',time:'today'})">
						<view class="num">{{ census.orderTimeCount.todayPrice }}</view>
						<view>今日成交额</view>
					</view>
					<view class="item" @click="goStatistics({type:'price',time:'yesterday'})">
						<view class="num">{{ census.orderTimeCount.proPrice }}</view>
						<view>昨日成交额</view>
					</view>
					<view class="item" @click="goStatistics({type:'price',time:'month'})">
						<view class="num">{{ census.orderTimeCount.monthPrice }}</view>
						<view>本月成交额</view>
					</view>
					<view class="item" @click="goStatistics({type:'order',time:'today'})">
						<view class="num">{{ census.orderTimeCount.todayCount }}</view>
						<view>今日订单数</view>
					</view>
					<view class="item" @click="goStatistics({type:'order',time:'yesterday'})">
						<view class="num">{{ census.orderTimeCount.proCount }}</view>
						<view>昨日订单数</view>
					</view>
					<view class="item" @click="goStatistics({type:'order',time:'month'})">
						<view class="num">{{ census.orderTimeCount.monthCount }}</view>
						<view>本月订单数</view>
					</view>
				</view>
			</view>
			<view class="public-wrapper">
				<view class="title">
					<text class="iconfont icon-xiangxishuju"></text>详细数据
				</view>
				<view class="nav acea-row row-between-wrapper">
					<view class="data">日期</view>
					<view class="browse">订单数</view>
					<view class="turnover">成交额</view>
				</view>
				<view class="conter">
					<view class="item acea-row row-between-wrapper" v-for="(item, orderListIndex) in list"
						:key="orderListIndex">
						<view class="data">{{ item.time }}</view>
						<view class="browse">{{ item.count }}</view>
						<view class="turnover">{{ item.price }}</view>
					</view>
				</view>
			</view>
			<Loading :loaded="loaded" :loading="loading"></Loading>
		</view>
	</view>
</template>
<script>
	import {
			mapGetters
		} from "vuex";
	import {
		statisticsApp,
		dataApp
	} from "@/api/admin";
	import Loading from "@/components/Loading";
	import { commissionLog } from "@/api/user.js"
	export default {
		name: "OrderIndex",
		components: {
			Loading
		},
		props: {},
		data: function() {
			return {
				census: {
					orderCount: {},
					orderTimeCount: {}
				},
				list: [],
				where: {
					page: 1,
					limit: 15
				},
				loaded: false,
				loading: false,
				data: {}
			};
		},
		mounted: function() {
			this.getIndex();
			this.getList();
			commissionLog({type: 0}).then(res=>{
				this.data = res.data
			})	
		},
		onReachBottom() {
			!this.loading && this.getList();
		},
		computed: mapGetters(["userInfo"]),
		methods: {
			goStatistics(query) {
				// this.$yrouter.push({
				//   path: "/storeManagementPack/pages/storeManagement/orderAdmin/Statistics/index",
				//   query
				// });
			},
			goAdminOrderList(types) {
				this.$yrouter.push({
					path: "/storeManagementPack/pages/storeManagement/orderAdmin/AdminOrderList/index",
					query: {
						types
					}
				});
			},
			getIndex: function() {
				var that = this;
				statisticsApp().then(
					res => {
						that.census = res.data;
						that.census.unpaidCount = that.census.orderCount.unpaidCount;
					},
					err => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: "none",
							duration: 2000
						});
					}
				);
			},
			getList: function() {
				var that = this;
				if (that.loading || that.loaded) return;
				that.loading = true;
				dataApp(that.where).then(
					res => {
						that.loading = false;
						that.loaded = res.data.length < that.where.limit;
						that.list.push.apply(that.list, res.data);
						that.where.page = that.where.page + 1;
					},
					err => {
						uni.showToast({
							title: err.msg || err.response.data.msg || err.response.data.message,
							icon: "none",
							duration: 2000
						});
					},
					300
				);
			},
			goRouter(url) {
				this.$yrouter.push({
					path: url
				});
			},
			goUserCash() {
					// 开通门店需要判断用户是否实名认证
					if (!this.userInfo.realName) return uni.showToast({
						title: '请先完成实名认证！',
						icon: "none",
						duration: 2000
					});
					this.goRouter(`/userPack/pages/user/promotion/UserCash/index`)
			}
		}
	};
</script>

<style scoped lang="less">
	.box {
		width: 100%;
		background-color: #00c17b;
		margin-bottom: 10rpx;
		color: #fff;
	}
</style>